<template>
	<view class="merchant-page">
		<!-- 筛选栏 -->
		<view class="filter-bar">
			<view class="filter-item" v-for="(item, index) in filterItems" :key="item.name"
				:class="{ active: activeFilter === index }" @click="changeFilter(index)">
				<text>{{ item.name }}</text>
				<uni-icons :type="item.icon" size="10" color="#999"
					:color="activeFilter === index ? '#ff6a6a' : '#999'"></uni-icons>
			</view>
		</view>

		<!-- 商家列表 -->
		<scroll-view scroll-y class="merchant-list">
			<merchant-card
				v-for="merchant in merchants"
				:key="merchant.id"
				:logo="merchant.avatar"
				:name="merchant.name"
				:is-official="merchant.isOfficial"
				:rating="merchant.rating"
				:sales="merchant.sales"
				:tags="merchant.tags"
				:promotions="merchant.promotions"
				@click="goToMerchant(merchant.id)"
			/>
		</scroll-view>
	</view>
</template>

<script setup>
import {
	ref
} from 'vue'

// 筛选条件
const filterItems = ref([{
	name: '综合排序',
	icon: 'bottom'
},
{
	name: '销量优先',
	icon: 'bottom'
},
{
	name: '距离优先',
	icon: 'bottom'
},
{
	name: '筛选',
	icon: 'funnel'
}
])

const activeFilter = ref(0)

// 商家数据
const merchants = ref([{
	id: 1,
	name: '名创优品旗舰店',
	isOfficial: true,
	avatar: 'https://images.unsplash.com/photo-1555396273-367ea4eb4db5?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=2074&q=80',
	rating: 4.8,
	sales: 2000,
	tags: ['官方认证', '品质保障', '极速发货', '7天无理由退换'],
	promotions: ['新人首单立减10元', '满99元包邮']
},
	// 可以添加更多商家数据
])

// 切换筛选条件
const changeFilter = (index) => {
	activeFilter.value = index
	// 这里可以添加筛选逻辑
}

// 跳转到商家详情
const goToMerchant = (id) => {
	uni.navigateTo({
		url: `/pages/merchant/detail?id=${id}`
	})
}
</script>

<style lang="scss" scoped>
.merchant-page {
	background-color: #f8f8f8;
	min-height: 100vh;
}

.nav-bar {
	display: flex;
	align-items: center;
	padding: 10px 15px;
	background-color: #fff;
	border-bottom: 1px solid #eee;

	.title {
		flex: 1;
		text-align: center;
		font-size: 16px;
		font-weight: bold;
	}
}

.filter-bar {
	display: flex;
	background-color: #fff;
	padding: 10px 15px;
	border-bottom: 1px solid #eee;

	.filter-item {
		flex: 1;
		display: flex;
		justify-content: center;
		align-items: center;
		font-size: 13px;
		color: #666;

		&.active {
			color: #ff6a6a;
		}
	}
}

.merchant-list {
	padding: 10px;
	height: calc(100vh - 90px);
}

.merchant-card {
	padding: 5px;
	background-color: #fff;
	border-radius: 8px;
	overflow: hidden;
	margin-bottom: 15px;
	box-shadow: 0 3px 10px rgba(0, 0, 0, 0.08);

	.merchant-avatar {
		width: 60px;
		height: 60px;
		border-radius: 8px;
		border: 1px solid #eee;
		background-color: #fff;
	}

	.merchant-info {
		padding: 0 5px;

		.merchant-name {
			font-size: 16px;
			font-weight: bold;
			margin-bottom: 5px;

			.merchant-type {
				font-size: 11px;
				padding: 2px 6px;
				background-color: #ff6a6a;
				border-radius: 3px;
				color: white;
				margin-left: 8px;
			}
		}

		.merchant-rating {
			display: flex;
			align-items: center;
			margin-bottom: 5px;
			font-size: 13px;

			.merchant-stars {
				display: flex;
				margin-right: 5px;
			}

			.merchant-order-count {
				color: #999;
				margin-left: 10px;
			}
		}

		.merchant-tags {
			display: flex;
			flex-wrap: wrap;
			gap: 5px;
			margin-bottom: 8px;

			.merchant-tag {
				font-size: 11px;
				padding: 2px 6px;
				background-color: #f5f5f5;
				border-radius: 3px;
				color: #666;
			}
		}

		.merchant-promotion {
			display: flex;
			align-items: center;
			font-size: 12px;
			color: #ff6a6a;
			margin-bottom: 5px;
		}
	}
}
</style>